package de.lazy.net.html;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class PageLoader {

	public static final String defaultUserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12"; 
	
	public static String loadHTMLFromUrl(String url, String userAgent) throws IOException{
	
		URL source = new URL("http://www.google.de/");
		URLConnection conn = source.openConnection();
		conn.addRequestProperty("User-Agent", userAgent);

		BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
		String str;
		StringBuilder builder = new StringBuilder();
		
		while ((str = in.readLine()) != null) {
			builder.append(str);
			builder.append("\n");
		}
		in.close();
		
		return builder.toString();
	
	}
	
	public static String loadHTMLFromUrl(String url) throws IOException{	
		return loadHTMLFromUrl(url, defaultUserAgent);
	}
	
	
}
